def solve(height):
    n = len(height)
    l = 0
    r = n - 1
    maxCapacity = min(height[l], height[r]) * (r - 1)
    while l < r:
        maxCapacity = max(maxCapacity, min(height[l], height[r]) * (r - l))
        if height[l] <= height[r]:
            l += 1
        else:
            r -= 1

    return maxCapacity


if __name__ == "__main__":
    height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
    print(solve(height))
